package org.dromara.germbank.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.germbank.domain.bo.BusOperationsAdvertisementBo;
import org.dromara.germbank.domain.bo.BusResearchSurveysBo;
import org.dromara.germbank.domain.vo.BusResearchSurveysVo;
import org.dromara.germbank.service.BusResearchSurveysService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 调研管理
 *
 * @author congxing
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/research")
public class BusResearchSurveysController extends BaseController {

    private final BusResearchSurveysService busResearchSurveysService;

    /**
     * 查询调研管理列表
     */
    @SaCheckPermission("germbank:surveys:list")
    @GetMapping("/list")
    public TableDataInfo<BusResearchSurveysVo> list(BusResearchSurveysBo bo, PageQuery pageQuery) {
        return busResearchSurveysService.queryPageList(bo,pageQuery);
    }

//    /**
//     * 新增调研管理
//     */
//    @SaCheckPermission("germbank:surveys:add")
//    @Log(title = "调研管理", businessType = BusinessType.INSERT)
//    @PostMapping
//    public R<Void> add(@Validated @RequestBody BusResearchSurveysBo bo) {
//        if (!busResearchSurveysService.checkSurveysNameUnique(bo)) {
//            return R.fail("新增调研'" + bo.getSurveysName() + "'失败，调研名称已存在");
//        }
//        return toAjax(busResearchSurveysService.insertSurveys(bo));
//    }

//    /**
//     * 修改保存调研
//     */
//    @SaCheckPermission("germbank:advertisement:edit")
//    @Log(title = "调研数据", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public R<Void> edit(@Validated @RequestBody BusResearchSurveysBo bo) {
//        if (!busResearchSurveysService.checkSurveysNameUnique(bo)) {
//            return R.fail("修改调研数据'" + bo.getSurveysName() + "'失败，调研已存在");
//        }
//        busResearchSurveysService.updateSurveysData(bo);
//        return R.ok();
//    }


    /**
     * 删除调研
     *
     * @param surveysCodes      * 删除调研code串
     */
    @SaCheckPermission("germbank:advertisement:remove")
    @Log(title = "调研", businessType = BusinessType.DELETE)
    @DeleteMapping("/{surveysCodes}")
    public R<Void> remove(@PathVariable Long[] surveysCodes) {
        busResearchSurveysService.
            deleteSurveysCodesDataByIds(Arrays.asList(surveysCodes));
        return R.ok();
    }
}
